<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>选择排序</title>
</head>
<body>
  <script>
    //选择排序，两两判断，记下最小值得索引。一趟比完之后互换。
    var arr = [3,1,4,2,23,6];
    for(var j=0;j<arr.length;j++){
    //取出最小索引
    var index = j;
    for(var i =j+1;i<arr.length;i++){
      if(arr[index]>arr[i]){
        index=i;
      }
    }
    var temp = arr[index];
    arr[index]=arr[j];
    arr[j]= temp;
  }
    console.log(arr)
  </script>
</body>
</html>